import { nextTick } from "vue";
import { defineStore } from "pinia";
import NProgress from "nprogress";

export const useAppStore = defineStore("app", {
    state: () => ({
        reloadFlag: true,
    }),
    actions: {
        async reloadPage(duration = 0) {
            NProgress.start();
            this.reloadFlag = false;
            await nextTick();
            if (duration) {
                setTimeout(() => {
                    this.reloadFlag = true;
                }, duration);
            } else {
                this.reloadFlag = true;
            }
            setTimeout(() => {
                document.documentElement.scrollTo({ left: 0, top: 0 });
            }, 100);
            NProgress.done();
        },
    },
});
